function LocationSummary(locations) {
    this.locations = locations || {};
}

LocationSummary.prototype = {
    append: function(another) {
        for (var location in another.locations) {
            if(!this.locations[location]){
                this.locations[location] = 0;
            }
            this.locations[location] = Math.add(this.locations[location], another.locations[location]);
        }
        return this;
    },

    appendLocationsInOneDay: function(locations) {
        var unit = Math.round(100.0 / locations.length);
        var alreadyCount = 0;
        for (var i = 0; i < locations.length; i++) {
            var value = unit;
            if (i == locations.length -1) {
                value = 100 - alreadyCount;
            }
            this._appendLocation(locations[i], value/100.0);
            alreadyCount += value;
        }
        return this;    
    },

    _appendLocation: function(location, count) {
        if(!this.locations[location]){
            this.locations[location] = 0;
        }
        this.locations[location] += count;
        return this;
    },

    total: function() {
        var result = 0;
        for(var location in this.locations){
            result += this.locations[location];
        }
        return result;
    }
};
